package priv.mill.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Map;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.Pattern;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import priv.mill.model.User;

//项目名/模块路径/方法路径

@Controller
@RequestMapping("/hello")
public class HelloController {
	/*
	 * 2:成功
	 * 3：有缓存
	 * 4：服务器出错，地址，少参数
	 * 5：	
	 */
	//@RequestMapping(value="/{addr}/info",method=RequestMethod.GET,params= {"name","age!=10"},headers= {"User-Agent"})//参数的过滤
	@GetMapping(value="/{addr}/info",headers= {"User-Agent"})
	@ResponseBody
	public String info(@PathVariable("addr") String abc) {// /hello/info
		return "<h1>这里是一个独立的Controller文件:"+abc+"</h1>";
	}
	
	@GetMapping("testcook")
	public @ResponseBody String cook(HttpServletRequest request) {
		Cookie[] cookies = request.getCookies();
		String cv="";
		for(Cookie cookie:cookies) {
			if(cookie.getName().equals("Webstorm-81601424")) {
				cv=cookie.getValue();
			}
		}
		return cv;
	}
	
	@GetMapping("testcook2")
	public @ResponseBody String cook2(
			@CookieValue("Pycharm-8352b8e3") String sv) {
		return sv;
	}
	
	@GetMapping("login")
	public @ResponseBody Object login(User user,Map<String, Object> map) {
		user.setUserName("刘德华");
		map.put("user", user);
		return user;
	}
	
	
	
	
	
	
}
